package com.test;

import java.sql.*;

/**
 * 连接测试
 */

public class JavaHive {
    public static void main(String[] args) {

        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;

        try {
            Class.forName("org.apache.hive.jdbc.HiveDriver");

            String url = "jdbc:hive2://192.168.200.200:10000/test02";

            connection = DriverManager.getConnection(url,"root","root");

            preparedStatement = connection.prepareStatement("SELECT * FROM table03");

            resultSet = preparedStatement.executeQuery();

            while(resultSet.next()){
                System.out.println("The result is :   "+resultSet.getString(1)+"--"+resultSet.getString(2));
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }finally{
            if (resultSet!=null){
                try {
                    resultSet.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }

            if (preparedStatement!=null){
                try {
                    preparedStatement.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }

            if (connection!=null){
                try {
                    connection.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }

        }


    }
}
